package com.ytc.information.controller;

import com.fasterxml.jackson.databind.annotation.JsonAppend;
import com.ytc.information.model.Deliver;
import com.ytc.information.model.Information;
import com.ytc.information.model.InformationList;
import com.ytc.information.service.InformationService;
import com.ytc.user.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

//对话消息类
@Controller
@RequestMapping("information")
public class InformationController {

    @Autowired
    private InformationService informationService;

    //获取对话记录
    @RequestMapping("getInformation")
    //@ResponseBody
    public String getInformation(Integer positionId,Integer userId, Model model){

        Information information = informationService.getInformation(positionId,userId);
        model.addAttribute("information",information);
        return "message/userDialog";

    }

    //新增对话记录
    @RequestMapping("addInformation")
    @ResponseBody
    public void addInformation(InformationList informationList,HttpServletRequest request){
        User user =(User) request.getSession().getAttribute("user");
        informationList.setSender(user.getUserId());//当前用户就是发信人
        informationService.addInformation(informationList);
    }

    //投递
    @RequestMapping("addDeliver")
    @ResponseBody
    public void addDeliver(Integer positionId, HttpServletRequest request){
        User user =(User) request.getSession().getAttribute("user");

        Deliver deliver = new Deliver();

        deliver.setUserId(user.getUserId());
        deliver.setUserRole(user.getUserRole());
        deliver.setPositionId(positionId);

        informationService.addDeliver(deliver);
    }

    //查询投递投递
    @RequestMapping("getDeliver")
    @ResponseBody
    public Deliver getDeliver(Integer positionId, HttpServletRequest request){
        User user =(User) request.getSession().getAttribute("user");

        Deliver deliver = new Deliver();

        deliver.setUserId(user.getUserId());
        deliver.setPositionId(positionId);

        return informationService.getDeliver(deliver);
    }

    //招聘方查询简历是否被投递
    @RequestMapping("getDeliver1")
    @ResponseBody
    public Deliver getDeliver1(Integer positionId, Integer userId){

        Deliver deliver = new Deliver();

        deliver.setUserId(userId);
        deliver.setPositionId(positionId);

        return informationService.getDeliver(deliver);
    }

}
